package com.pinyuana.dragongame.adapter

import androidx.appcompat.widget.AppCompatImageView
import com.aliyun.auikits.aicall.base.SessionHistory
import com.blankj.utilcode.util.SizeUtils
import com.cardetective.shopcar.R
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.makeramen.roundedimageview.RoundedImageView
import com.pinyuana.dragongame.network.model.HomeChatListModel
import top.wangchenyan.common.ext.load

/**
 *
 * */
class HomeChatAdapter : BaseQuickAdapter<SessionHistory, BaseViewHolder>(R.layout.item_home_chat) {

    // 添加本地头像资源数组
    private val localAvatars = listOf(
        R.mipmap.icon_header_normal,
        R.mipmap.icon_header_normal01,
        R.mipmap.icon_header_normal02,
        R.mipmap.icon_header_normal,
        R.mipmap.icon_header_normal01,
        R.mipmap.icon_header_normal02,
        R.mipmap.icon_header_normal,
        R.mipmap.icon_header_normal01,
        R.mipmap.icon_header_normal02,
        R.mipmap.icon_header_normal,
        R.mipmap.icon_header_normal01,
        R.mipmap.icon_header_normal02,
        R.mipmap.icon_header_normal,
        R.mipmap.icon_header_normal01,
        R.mipmap.icon_header_normal02
    )

    override fun convert(holder: BaseViewHolder, item: SessionHistory) {
        with(holder) {
            holder.setText(R.id.tv_des,item.lastMessage)
            holder.setText(R.id.tv_title,item.nickName)
            val iv_header = getView<AppCompatImageView>(R.id.iv_header)
            // 生成随机索引并设置本地图片
//            val randomIndex = (0 until localAvatars.size).random()
//            iv_header.setImageResource(localAvatars[randomIndex])

            when (item.aiImgType) {
                "1" -> {
                    iv_header.setImageResource(localAvatars[0])
                }
                "2" -> {
                    iv_header.setImageResource(localAvatars[1])
                }
                "3" -> {
                    iv_header.setImageResource(localAvatars[2])
                }
                "4" -> {
                    iv_header.setImageResource(localAvatars[3])
                }
                "5" -> {
                    iv_header.setImageResource(localAvatars[4])
                }
                "6" -> {
                    iv_header.setImageResource(localAvatars[5])
                }
                "7" -> {
                    iv_header.setImageResource(localAvatars[6])
                }
                "8" -> {
                    iv_header.setImageResource(localAvatars[7])
                }
                "9" -> {
                    iv_header.setImageResource(localAvatars[8])
                }
                "10" -> {
                    iv_header.setImageResource(localAvatars[9])
                }
                else -> {
                    iv_header.setImageResource(localAvatars[0])
                }
            }

        }
    }
}